﻿
var httpurl = "http://app.sucslife.com:8088/";

function httppost(url,data,call,error) {
    $.ajax({
        type: "post",
        url: httpurl + url,
        data: JSON.stringify(data),
        dataType: 'json',
        async: true,
        success: function (data) {
            call(data);
        },
        error: function (errorx) {
            error(errorx);
         
        }
    });
}
function httpget(url, data, call, error) {
    $.ajax({
        type: "get",
        url: httpurl + url,
        data: data,
        dataType: 'json',
        async: true,
        success: function (data) {
            call(data);
        },
        error: function (errorx) {
            error(errorx);

        }
    });
}

function GetRequest() {
    var url = decodeURI(decodeURI(location.search)); //获取url中"?"符后的字串，使用了两次decodeRUI解码
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
        return theRequest;
    }
}

var arrData = [];

window.setUserInfoData = function (call) {
    var n = new Date().getTime();

    arrData.push({ time: n, data: call });
    console.log(arrData)
    return n;
}
window.getUserlistData = function (time) {
    for (var n = 0; n < arrData.length; n++){
        if (arrData[n].time == time) {
            return arrData[n].data;
        }
    }
    return {};
}
window.getUserInfoData = function (time) {
    return parent.window.getUserlistData(time);
}
var Resquest = GetRequest();

var pagecalllist_config = []


window.registraror = function (name, call) {
    pagecalllist_config.push({
        name: name,
        call: call
    })
}

window.addlistData = function (name, call) {
    parent.window.registraror(name, call);
}


window.LoopSendData = function (name, data) {
    for (var f = 0; f < pagecalllist_config.length; f++) {
        if (pagecalllist_config[f].name == name) {
            pagecalllist_config[f].call(data);

        }

    }
}

window.sendlistData = function (name, data) {
    parent.window.LoopSendData(name, data);
}

Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份 
        "d+": this.getDate(),                    //日 
        "h+": this.getHours(),                   //小时 
        "m+": this.getMinutes(),                 //分 
        "s+": this.getSeconds(),                 //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds()             //毫秒 
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
} 

var formatJson = function (json, options) {
    var reg = null,
        formatted = '',
        pad = 0,
        PADDING = '    ';
    options = options || {};
    options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
    options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
    if (typeof json !== 'string') {
        json = JSON.stringify(json);
    } else {
        json = JSON.parse(json);
        json = JSON.stringify(json);
    }
    reg = /([\{\}])/g;
    json = json.replace(reg, '\r\n$1\r\n');
    reg = /([\[\]])/g;
    json = json.replace(reg, '\r\n$1\r\n');
    reg = /(\,)/g;
    json = json.replace(reg, '$1\r\n');
    reg = /(\r\n\r\n)/g;
    json = json.replace(reg, '\r\n');
    reg = /\r\n\,/g;
    json = json.replace(reg, ',');
    if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
        reg = /\:\r\n\{/g;
        json = json.replace(reg, ':{');
        reg = /\:\r\n\[/g;
        json = json.replace(reg, ':[');
    }
    if (options.spaceAfterColon) {
        reg = /\:/g;
        json = json.replace(reg, ':');
    }
    (json.split('\r\n')).forEach(function (node, index) {
        var i = 0,
            indent = 0,
            padding = '';

        if (node.match(/\{$/) || node.match(/\[$/)) {
            indent = 1;
        } else if (node.match(/\}/) || node.match(/\]/)) {
            if (pad !== 0) {
                pad -= 1;
            }
        } else {
            indent = 0;
        }

        for (i = 0; i < pad; i++) {
            padding += PADDING;
        }

        formatted += padding + node + '\r\n';
        pad += indent;
    }
    );
    return formatted;
};